package com.passengerflowmanagementsystem.statistics.utils;

import com.hikvision.artemis.sdk.*;
import com.hikvision.artemis.sdk.config.ArtemisConfig;

import java.util.HashMap;
import java.util.Map;


/**
 * 调取海康api公用方法
 *
 * @author sheng
 * @date 2024-11-25
 */
public class GetCameraPreviewURL {


    public static String GetCameraPreviewURL(String url,String body) {


        /**
         * STEP1：设置平台参数，根据实际情况,设置host appkey appsecret 三个参数.
         */
        ArtemisConfig artemisConfig = new ArtemisConfig();
        artemisConfig.host = "192.168.110.60:443"; // artemis网关服务器ip端口
        artemisConfig.appKey = "22250685";  // 秘钥appkey
        artemisConfig.appSecret = "TvgBgbKobEQiFoJUDZCM";// 秘钥appSecret

        /**
         * STEP2：设置OpenAPI接口的上下文
         */
        final String ARTEMIS_PATH = "/artemis";

        /**
         * STEP3：设置接口的URI地址
         */
        //final String previewURLsApi = ARTEMIS_PATH + "/api/video/v1/cameras/previewURLs";
        final String previewURLsApi = ARTEMIS_PATH + url;
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";

        /**
         * STEP5：组装请求参数
         */
//        JSONObject jsonBody = new JSONObject();
//        jsonBody.put("cameraIndexCode", "748d84750e3a4a5bbad3cd4af9ed5101");
//        jsonBody.put("streamType", 0);
//        jsonBody.put("protocol", "rtsp");
//        jsonBody.put("transmode", 1);
//        jsonBody.put("expand", "streamform=ps");
//        String body = jsonBody.toJSONString();
        /**
         * STEP6：调用接口
         */
        String result = "";
        try {
            result = ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path, body, null, null, contentType , null);// post请求application/json类型参数

        }catch (Exception ex){
            throw new RuntimeException(ex);
        }
        return result;
    }


}
